<template><view>
  <view class="errormsgDiv" v-if="nodata">
    <view class="errormsg">\（￣︶￣）/</view>
    <view class="errormsg2">没有相关数据</view>
  </view>
  <view  class="cu-list menu"  v-else> 
				<view class="cu-item arrow" :key="index"  v-for="(item,index) in items"  @click="jump(item.id)">
					<view class="content padding-tb-sm">
						<view >
						  小区:{{item.shop_name}}</view>
						<view class="text-gray text-sm">
						  日期:{{item.visit_date}}</view>
					</view>
					<view class="content padding-tb-sm">
						<view >
						  访客:{{item.name}}</view>
						<view class="text-gray text-sm">
						  人数:{{item.number_of_people}}人</view>
					</view>
					<view class="action"  >
						<view v-if="item.status == 0" class="cu-tag round bg-orange light">未使用</view>
						<view v-if="item.status == 2" class="cu-tag round bg-olive light">己使用</view>
						<view v-if="item.status == 3" class="cu-tag round bg-blue light">已过期</view>
					</view>
				</view>
			
	</view>	
	 <view style="height: 80upx;"></view>
	<view   class="fixed-btn cu-btn block bg-blue  lg"  @click="add">{{addText}}</view>
</view>

</template>
<script>
	import beeApp from '../../beeApp.js'
	export default {
		data() {
			return {
				items: [],
				page: 1,
				mounted: 0,
				nodata:0,
				loadding:0,
				userInfo:{},
				lastpage:0,
				addText:'访客登记'
			}
		},
		onLoad(option) {
		  if(option.pid){
			  this.pid = option.pid;
		  }
	
		  beeApp.getUserInfo((userInfo)=>{
			  this.userInfo = userInfo;
			  this.getList();
		  })
		  
		  
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() { 
			this.getList(1);
			uni.stopPullDownRefresh();
		},
		onShow:function(){
			var reload = beeApp.getPageData("pages/visitor/index","reload");
			console.log("reload",reload)
			if(reload==1){
				beeApp.setPageData("pages/visitor/index",{reload:0});
				this.getList(1);
			}
		 
		},
		methods: {
		  getList:function(reload=0){
			  var _this = this;
			  if(reload==1){
				  this.page=1;
				  this.loadding=0;
				  this.lastpage=0;
				  this.items=[];
			  }
			   var params = {
				    page: this.page,
					owner_user_id:this.userInfo.user_id,
					pid:this.pid,
					order:'id desc'
			   };
			 if ( this.loadding ==1 || this.lastpage==1) {
				   return false;
			   }
			   _this.loadding=1;
			   beeApp.api("api/community_visitor/get", params, function(res) {
						_this.loadding=0;
                        if (res.code != 200) {
                            beeApp.alert(res.msg);
                            return;
                        }
                        // console.log(res);
                        if (res.data.list.length === 0) {
                            _this.lastpage = 1;
                        }

                        var items = _this.items;
                        _this.items = items.concat(res.data.list);
                        _this.page++;
                        if(_this.items.length === 0){
                            _this.nodata=1;
                        }else{
							_this.nodata=0;
						}
                    });
		  },
		  add:function(){
			  uni.navigateTo({
				 url:"/pages/visitor/add"
			  })	
		  },
		  jump:function(id){
               uni.navigateTo({
				  url:"/pages/visitor/detail?id="+id
			   })	
          },
	   }
		
}
</script>


<style>
</style>
